/*
** main.c for mysh in /home/nadali_t//local/svn/tek2ed/minishell1
** 
** Made by thomas nadalie
** Login   <nadali_t@epitech.net>
** 
** Started on  Thu Nov  8 12:23:46 2012 thomas nadalie
** Last update Thu Nov  8 12:26:01 2012 thomas nadalie
*/

#include	<stdio.h>
#include	<stdlib.h>
#include	<unistd.h>
#include	"my.h"

void		init_struct(t_list **list)
{
  t_list	*new_list;

  if ((new_list = malloc(sizeof(*list))) == NULL)
    my_put_error("Malloc failed in init_struct()\n");
  new_list->stop = 0;
  new_list->end = 0;
}

char		**make_env(char **env)
{
  char		**new_env;

  if ((new_env = malloc(sizeof(*env) * my_tablen(env) + 2)) == NULL)
    return (env);
  return (new_env);
}

char		**make_read(char **new_env)
{
  char		*buffer;
  char		**cmd;
  int		ret;
  char		**path;

  ret = 1;
  if ((buffer = malloc(sizeof(*buffer) * 5000)) == NULL)
    return (new_env);
  buffer = my_bzero(buffer, 5000);
  aff_prompt(new_env);
  if ((ret = read(0, buffer, 5000)) == -1)
    return (new_env);
  buffer = epur_str(buffer);
  path = get_path(new_env);
  
  //Manque 1st path
  cmd = my_str_to_wordtab(buffer);
  new_env = exec_cmd(path, cmd, new_env);
  return (new_env);
}

int		main(int ac, char **av, char **env)
{
  int		i;
  char		**new_env;

  i = 0;
  new_env = my_env(env);
  if (ac == 1)
    {
      while (i != 1)
	{
	  if (new_env[i] == NULL)
	    return (-1);
	  new_env = make_read(new_env);
	}
    }
  return (0);
}
